package com.luojun.servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.luojun.entity.Car;
import com.luojun.entity.Commodity;
import com.luojun.entity.User;
import com.luojun.service.CarService;
import com.luojun.service.UCommodityService;

/**
 * Servlet implementation class ToPersonalCenter
 */
@WebServlet("/ToPersonalCenter")
public class ToPersonalCenter extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ToPersonalCenter() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		User user = (User)session.getAttribute("user");
		if(user==null){
			request.getRequestDispatcher("ToLogin").forward(request, response);
		}
		
		UCommodityService ucs = new UCommodityService();
		CarService cs = new CarService();
		List<Car> list = cs.findsell(user.getUserId());
		List<Commodity> overList =ucs.findStatusAndUser(user.getUserId(),0);
		List<Commodity> ingList =ucs.findStatusAndUser(user.getUserId(),1);
		List<Commodity> checkList =ucs.findStatusAndUser(user.getUserId(),2);
		List<Commodity> sellList = ucs.findsell(list);
		request.setAttribute("nickname", session.getAttribute("nickname"));
		request.setAttribute("overList", overList);
		request.setAttribute("ingList", ingList);
		request.setAttribute("checkList", checkList);
		request.setAttribute("sellList", sellList);
		request.getRequestDispatcher("WEB-INF/jsp/Personalcenter.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
